﻿using System;
using System.IO.IsolatedStorage;
using System.Collections.Generic;

namespace studPage.Model
{
    public class Helper
    {
        internal static string GetLatestTeacherId(string searchTerm)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(searchTerm))
            {
                return IsolatedStorageSettings.ApplicationSettings[searchTerm].ToString();
            }
            else
            {
                return "0";
            }
        }

        internal static void SaveLatestTeacherId(string searchTerm, string latestId)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(searchTerm))
            {
                IsolatedStorageSettings.ApplicationSettings[searchTerm] = latestId;
            }
            else
            {
                IsolatedStorageSettings.ApplicationSettings.Add(searchTerm, latestId);
            }
        }

        internal static string[] GetSearchTermHistory()
        {
            List<string> searchHistory = new List<string>();

            foreach (var item in IsolatedStorageSettings.ApplicationSettings.Keys)
            {
                searchHistory.Add(item.ToString());
            }

            return searchHistory.ToArray();
        }
    }
}
